from http_factory import HttpClientFactory
from exceptions import RequestError, ResponseError
import time

def main():
    # 创建同步客户端
    client = HttpClientFactory.create(
        async_mode=False,
        base_url='http://localhost:8000',
        timeout=30,
        max_retries=3
    )
    
    start_time = time.time()
    
    try:
        # 测试GET请求
        response = client.get('/messages/history')
        print(f"同步GET请求结果: {response.data}")
        
        # 测试POST请求
        response = client.post('/messages/', data={'message': 'Hello from sync client'})
        print(f"同步POST请求结果: {response.msg}")
        
        # 测试状态设置
        response = client.post('/messages/state', params={'key': 'test_sync', 'value': 'value_sync'})
        print(f"同步状态设置结果: {response.msg}")
        
        # 测试状态获取
        response = client.get('/messages/state/test_sync')
        print(f"同步状态获取结果: {response.data}")
        
    except RequestError as e:
        print(f"请求错误: {str(e)}")
    except ResponseError as e:
        print(f"响应错误: {str(e)}")
        
    print(f"同步请求总耗时: {time.time() - start_time:.2f}秒")

if __name__ == '__main__':
    main() 